package com.tianyang.yukuaifu.business.main.view;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.tianyang.yukuaifu.R;
import com.tianyang.yukuaifu.base.BaseTitleActivity;
import com.tianyang.yukuaifu.business.login.provider.LoginOpenProvider;
import com.tianyang.yukuaifu.business.main.contract.SettingCenterContract;
import com.tianyang.yukuaifu.business.main.presenter.SettingCenterPresenter;
import com.tianyang.yukuaifu.business.main.provider.MainOpenProvider;
import com.tianyang.yukuaifu.common.interfaces.UrlConstants;
import com.tianyang.yukuaifu.module.dialog.RemindDialog;
import com.tianyang.yukuaifu.module.dialog.interfaces.TwoBtnClickListener;
import com.tianyang.yukuaifu.utils.VersionUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Description：设置中心
 */
public class SettingCenterActivity extends BaseTitleActivity implements SettingCenterContract.View {

    @BindView(R.id.versionTv)
    TextView versionTv;

    private SettingCenterContract.Presenter mPresenter;

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_setting_center;
    }

    @Override
    protected void initView() {
        super.initView();
        commonTitle.setTitle("设置");
        mPresenter = new SettingCenterPresenter(this);
    }

    @OnClick({R.id.rlPermissionSetting, R.id.rlUpdatePsw, R.id.rlLogoff, R.id.rlPrivateAgree, R.id.outLoginBtn, R.id.rlSettleManage})
    public void onClick(View view) {
        if (!isRespondEvent()) return;
        switch (view.getId()) {
            case R.id.rlPermissionSetting:
                MainOpenProvider.getInstance().openPermissionSettingActivity(mContext);
                break;
            case R.id.rlUpdatePsw:
                LoginOpenProvider.getInstance().openUpdateLoginPwdActivity(mContext);
                break;
            case R.id.rlLogoff:
                logoff();
                break;
            case R.id.rlPrivateAgree:
                MainOpenProvider.getInstance().openBrowserX5Activity(mContext, "《隐私政策》", UrlConstants.PRIVACY_POLICY);
                break;
            case R.id.outLoginBtn:
                mPresenter.exitApp();
                break;
            case R.id.rlSettleManage:
                MainOpenProvider.getInstance().openSettleManageActivity(mContext);
                break;
            default:
                break;
        }
    }

    @Override
    protected void initData() {
        String versionName = VersionUtils.getVersionName(mContext);
        if (!TextUtils.isEmpty(versionName)) {
            versionTv.setText("当前版本 " + versionName);
        }
    }

    private void logoff() {
        new RemindDialog(this)
                .title("警告")
                .content("注销后将无法恢复，请谨慎操作！！！")
                .cancel("再看看")
                .comfirm("我要注销")
                .listener(new TwoBtnClickListener() {
                    @Override
                    public void onLeftClick() {

                    }

                    @Override
                    public void onRightClick() {
                        mPresenter.logOff();
                    }
                })
                .show();
    }

    @Override
    protected boolean hasBindEventBus() {
        return false;
    }

    @Override
    public void setPresenter(SettingCenterContract.Presenter presenter) {
        this.mPresenter = presenter;
    }

    @Override
    public Context getContext() {
        return this;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mPresenter != null) {
            mPresenter.onDestroyPresenter();
            mPresenter = null;
        }
    }
}
